<?php

namespace App\Datas;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class DrawingBoardPrepare
{
    
    public static function getDrawingBoardPrepare($lange, $deviceId, $userId){

        if (!empty($deviceId)) {
            $isPay = DB::table('pay_order')->where('status',1)->where('device_id',$deviceId)->count();
            if ($isPay > 0) {
                return [];
            }
        }
        if (!empty($userId)) {
            $isPay = DB::table('pay_order')->where('status',1)->where('user_id',$userId)->count();
            if ($isPay > 0) {
                return [];
            }
        }
        $count = DB::table('drawing_board_prepare')->where('lang', $lange)->count();
        if ($count == 0) {
            $lange = 'en';
        }
        
        $data = DB::table('drawing_board_prepare')
                    ->where('status',1)
                    ->where('lang',$lange)
                    ->orderBy('sort','desc')
                    ->orderBy('id','desc')
                    ->select('id','name','describition','sort')
                    ->get();
        return $data;

    }


    public static function getFirst($id){

        $data = DB::table("drawing_board_prepare")->where('id',$id)->first();

        return $data ? (array)$data : [];

    }

    

   
}